package cn.edu.nju.software.zp13.assignment5.service.soapMessage;


import java.io.IOException;
import java.io.InputStream;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPException;
import javax.xml.soap.SOAPMessage;


public abstract class SOAPMsgProducer {
	protected SOAPMessage soapMessage;

	public SOAPMsgProducer() {
		try {
			soapMessage = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage();
		} catch (SOAPException e) {
			e.printStackTrace();
		}
	}
	
	public SOAPMsgProducer(InputStream in){
			try {
				soapMessage = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL).createMessage(new MimeHeaders(),in);
			} catch (IOException | SOAPException e) {
				e.printStackTrace();
			}
	}
	
	public SOAPMessage produceSOAPMessage() {
		processSOAPMsg();
		return soapMessage;
	}

	public abstract void processSOAPMsg();
	
}
